package com.gitee.feizns.itrip.personal.biz.controller;

import com.gitee.feizns.itrip.personal.beans.dto.Dto;
import com.gitee.feizns.itrip.personal.biz.entity.ao.ForAcceptSearchHotelRoomByHotel;
import com.gitee.feizns.itrip.personal.biz.entity.vo.ForViewGetImg;
import com.gitee.feizns.itrip.personal.biz.entity.vo.ForViewHotelLable;
import com.gitee.feizns.itrip.personal.biz.entity.vo.ForViewSearchHotelRoomByHotel;
import com.gitee.feizns.itrip.personal.biz.service.HotelRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author feizns
 * @since 2019/1/8 0008
 */
@RestController
@RequestMapping("/api/hotelroom")
public class HotelRoomController {

    @Autowired
    private HotelRoomService hotelRoomService;

    @GetMapping("/getimg/{roomId}")
    public Dto<List<ForViewGetImg>> getImg(@PathVariable Integer roomId) {
        return Dto.getSuccessDto("获取酒店图片房型成功", hotelRoomService.getImg(roomId));
    }

    @GetMapping("/queryhotelroombed")
    public Dto<List<ForViewHotelLable>> queryHotelRoomBed() {
        return Dto.getSuccessDto("获取成功", hotelRoomService.queryHotelRoomBed());
    }

    @PostMapping("/queryhotelroombyhotel")
    public Dto<List<List<ForViewSearchHotelRoomByHotel>>> queryHotelRoomByHotel(@RequestBody ForAcceptSearchHotelRoomByHotel search) {
        List<List<ForViewSearchHotelRoomByHotel>> result = new ArrayList<>();
        List<ForViewSearchHotelRoomByHotel> rooms = hotelRoomService.queryHotelRoomByHotel(search);
        if ( rooms != null )
            rooms.stream().forEach(item -> result.add(Arrays.asList(item)));
        return Dto.getSuccessDto("获取成功", result);
    }

}
